package com.jeeplus.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.ConnectionHolder;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import java.sql.SQLException;

/**
 * @author Administrator
 * @title: JdbcUtils
 * @projectName JeePlus
 * @description: TODO
 * @date 2019/9/512:15
 */

public class JdbcUtils {
    /*日志*/
    protected Logger logger = LoggerFactory.getLogger(getClass());
 /**
  * 删除连接
  *
  * @Author LH
  * @Description //TODO
  * @Date 12:16 2019/9/5
  * @param jdbcTemplate
  * @return void
  **/
    public  void released(JdbcTemplate jdbcTemplate) {
        try {
            System.out.println("正在关闭");
            ConnectionHolder holder = (ConnectionHolder) TransactionSynchronizationManager.getResource(jdbcTemplate.getDataSource());
            System.out.println("准备关闭");
            holder.getConnection().close();
            // set holder isVoid true
            System.out.println("set holder isVoid true");
            holder.unbound();
            holder.released();
            holder.clear();
        }
        catch (Exception e){
            e.printStackTrace();
        }

    }
}
